package com.itheima.duotai2;

public class Test {

    public static void main(String[] args) {
        Animal a = getAnimal();
  /*      Dog a = getDog();
        a.eat();
        Cat a1= getCat();
        a1.eat();*/
        a.eat();
        if(a instanceof  Dog){
            Dog dog= (Dog) a;
            dog.watchHome();
        }


    }

    public static Cat getCat() {

        return new Cat();
    }

    public static Dog getDog() {
        return new Dog();
    }

    public static Animal getAnimal() {
    return new Dog();
        //  return new Cat();
    }
}

abstract class Animal {
    public abstract void eat();
}

class Dog extends Animal {
    public void watchHome(){
        System.out.println("看家");
    }
    @Override
    public void eat() {
        System.out.println("狗吃狗粮");
    }
}

class Cat extends Animal {
    @Override
    public void eat() {
        System.out.println("猫吃猫粮");
    }
}